//
//  YDStatusBottomView.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/13.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit

class YDStatusBottomView: UIView {
    var retweetButton:UIButton?
    var commentButton:UIButton?
    var unlikeButton:UIButton?
    
//    供外界赋值
    var statusViewModel:YDStatusViewModel?{
        didSet{
     
            
//          设置title
            retweetButton?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            commentButton?.setTitle(statusViewModel?.commentCountStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
            
        }
    
    }
    


    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    设置视图
    private func setupUI(){
        backgroundColor = UIColor.whiteColor()
//        添加控件
         retweetButton = addChildButtons("timeline_icon_retweet", title: "转发")
         commentButton = addChildButtons("timeline_icon_comment", title: "评论")
         unlikeButton =  addChildButtons("timeline_icon_unlike", title: "赞")
        let line1 = addChildLine()
        let line2 = addChildLine()
//        添加约束
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
        }
        
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.top.trailing.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        }
//        lineView
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton!.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton!.snp_trailing)
        }

        

        
        
    }
    func addChildButtons(imageName:String,title:String) -> UIButton{
        let button = UIButton()
//        设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
//    设置图片
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
//        添加按钮
        addSubview(button)
        return button
    }
    func addChildLine() -> UIImageView{
    let image = UIImageView(imageName: "timeline_card_bottom_line")
    addSubview(image)
        return image
    }
}
